package com.bt.supercodegenerator.gen;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

/**
 * @author zkx
 * @Date 2022/7/5 14:58
 */
public class MybatisPlusGenerator {

	/**
	 * 官方地址 https://baomidou.com/pages/981406/#%E6%95%B0%E6%8D%AE%E5%BA%93%E9%85%8D%E7%BD%AE-datasourceconfig
 	 */

	/**
	 * jdbc url username password
	 */
	private static final String URL = "jdbc:mysql://172.17.0.47:3306/cu_scrm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&zeroDateTimeBehavior=convertToNull";
	private static final String USERNAME = "syjava";
	private static final String PASSWORD = "sy123.com";

	/**
	 * 作者
	 */
	private static final String AUTHOR = "zkx";
	/**
	 * 输出目录
	 */
	private static final String OUTPUT_DIR = "C:\\Users\\SuperX\\Desktop";
	/**
	 * 父包名 com.xxx
	 */
	private static final String PARENT = "org.cuour";
	/**
	 * 模块名
	 */
	private static final String MODULE_NAME = "scrm";
	/**
	 * mapper.xml生成路径
	 */
	private static final String PATH_INFO = OUTPUT_DIR + "\\mapper";
	/**
	 * 表名
	 */
	private static final String TABLE_NAME = "ads_account_rebate_log";

	public static void main(String[] args) {
		FastAutoGenerator.create(URL, USERNAME, PASSWORD)
				.globalConfig(builder -> builder.author(AUTHOR)
//							.enableSwagger() //开启swagger模式
						.fileOverride() // 覆盖已生成文件
						.dateType(DateType.TIME_PACK)
						.disableOpenDir()
						.commentDate("yyyy-MM-dd")
						.outputDir(OUTPUT_DIR))
				.packageConfig(builder -> {
					builder.parent(PARENT)
							.moduleName(MODULE_NAME)  // 设置父包模块名
							.pathInfo(Collections.singletonMap(OutputFile.xml, PATH_INFO)); // mapper.xml生成路径
				})
				.strategyConfig(builder -> {
					builder.addInclude(TABLE_NAME)
							.enableCapitalMode() // 设置大写命名
//							.addTablePrefix("") // 设置过滤表前缀

							// Entity策略配置
							.entityBuilder()
							.enableLombok() // 开启lombok模型
							.enableChainModel() // 开启链式调用
							.naming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略
							.enableTableFieldAnnotation() // 开启生成实体时生成字段注解

							// Service 策略配置
							.serviceBuilder()
							.formatServiceFileName("%sService"); // 格式化 service 接口文件名称
				})
				.templateEngine(new VelocityTemplateEngine())
				.execute();

	}
}
